package com.enzoism.springboot.dive.list;

import com.enzoism.springboot.dive.model.UsrModel;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 模拟两个List进行合并
 */
public class AListFlatMap {
    public static void main(String[] args) {
        List<String> usrIdList = Arrays.asList("北京","上海","无锡");
        List<Long> clkNumList = Arrays.asList(12121L,34343L,454354L);
        // 场景一：嵌套List合并一个List
        AListFlatMap.嵌套List合并一个List(usrIdList,clkNumList);
    }

    /**
     * 将 List<List<UsrModel>> 转化到一个List中
     */
    private static void 嵌套List合并一个List(List<String> usrIdList, List<Long> clkNumList) {
        List<List<UsrModel>> lists = usrIdList.stream().map(usrId -> clkNumList.stream().map(clkNum -> new UsrModel(usrId, clkNum, 5)).collect(Collectors.toList())).collect(Collectors.toList());
        List<UsrModel> collect = lists.stream().flatMap(Collection::stream).collect(Collectors.toList());
        collect.forEach(System.out::println);
    }
}
